// TOWN SCRIPT
//    Town 4: Attic

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documentation. States you write
// yourself should be numbered from 10-100.

// flags:
//

begintownscript;

variables;

short choice;

body;

beginstate INIT_STATE;
	turn_off_training(TRUE);
	set_crime_tolerance(1);

	// reset flag
	set_flag(4, 1, 0);

	// restore vortex if summoned, but not killed
	if ((get_flag(3, 1) > 0) && (get_flag(101, 3) == 0))
		spawn_creature(6);
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
break;

beginstate 10;
	block_entry(TRUE);
	move_to_new_town(3, 40, 11);
break;

beginstate 11;
	if ((has_item(462)) && (get_flag(50, 6) > 0)) {
		if ((get_flag(4, 0) == 0) && (get_flag(4, 1) == 0)) {
			set_flag(4, 1, 1);
			reset_dialog();
			add_dialog_str(0, "Do you use your flute and try to unfreeze a vortex?", 0);
			add_dialog_choice(0, "Yes");
			add_dialog_choice(1, "No");
			choice = run_dialog(1);
			if (choice == 1) {
				set_flag(4, 0, 1);
				message_dialog("With a short little flute note, you hear a loud whoosh start up on the other side of the door.", "Mmmmm, vortexes...");
				spawn_creature(6);
			}
		}
	}
break;
